#pragma once

#include "WebkitCOM.h"

class CWebkitView;
class WebPolicyDelegate : public IWebPolicyDelegate {
public:
	WebPolicyDelegate(CWebkitView* owner, IWebPolicyDelegate* defaultPolicyDelegate)
		: m_refCount(0), m_owner(owner) { m_default = defaultPolicyDelegate; }
	~WebPolicyDelegate() { m_default = nullptr; }

	// IUnknown
	HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject) override;
	ULONG STDMETHODCALLTYPE AddRef() override;
	ULONG STDMETHODCALLTYPE Release() override;

	// IWebPolicyDelegate
	HRESULT STDMETHODCALLTYPE decidePolicyForNavigationAction(IWebView* webView, IPropertyBag* actionInformation, IWebURLRequest* request, IWebFrame* frame, IWebPolicyDecisionListener* listener) override;
	HRESULT STDMETHODCALLTYPE decidePolicyForNewWindowAction(IWebView* webView, IPropertyBag* actionInformation, IWebURLRequest* request, BSTR frameName, IWebPolicyDecisionListener* listener) override;
	HRESULT STDMETHODCALLTYPE decidePolicyForMIMEType(IWebView* webView, BSTR type, IWebURLRequest* request, IWebFrame* frame, IWebPolicyDecisionListener* listener) override;
	HRESULT STDMETHODCALLTYPE unableToImplementPolicyWithError(IWebView* webView, IWebError* error, IWebFrame* frame) override;

protected:
	IWebPolicyDelegatePtr m_default;
	CWebkitView* m_owner;

private:
	ULONG m_refCount;
};
